<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>保单结算确认</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<body class="iframeBody">
<form id="insPlcStl_form">
    <div class="fieldset1 tabel_col tabel_col_1 clearFix">
        <div class="fieldBox col_100">
            <div class="label">结算单号</div>
            <div class="field">
                <input name="stlNo" id="stlNo" type="text" class="ui-textbox" value="${stlNo}" readonly="readonly"
                	validate="{required:true,maxlength:20}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">结算金额</div>
            <div class="field">
                <input name="stlAmt" id="stlAmt" type="text" class="ui-textbox" value="" readonly="readonly" 
                	validate="{required:true,number:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">实际结算金额</div>
            <div class="field">
                <input name="actStlAmt" id="actStlAmt" type="text" class="ui-textbox" value="" readonly="readonly"
                       validate="{required:true,number:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">结算时间</div>
            <div class="field">
                <input name="stlTm" id="stlTm" type="text" class="ui-datepicker" value="" validate="{required:true}">
                <span class="requiredSymbol">*</span>
            </div>
        </div>
        <div class="fieldBox col_100">
            <div class="label">备注</div>
            <div class="field">
                <textarea name="stlRem" id="stlRem" class="ui-textarea l-textarea" cols="30" rows="4" value=""
                          validate="{required:false,maxlength:100}"></textarea>
            </div>
        </div>
    </div>
    <div class="formBtns notRight" style="text-align: center;">
    	<!-- 保单结算状态INS0002：10未开始 20未结算 30待确认 40已结算 -->
    	<input type="text" style="display: none;" id="stlStsCd" name="stlStsCd" value="40">
        <span id="saveInsPlcStl_Btn" class="sq-button sq-button-round">
        <i class="sqBtnIco_10"></i>结算</span>
        <input type="reset" id="resetBtn" class="l-button l-button-reset Hide">
    </div>
</form>
<script>
    $(function () {
        var insPlcStlId = "${id}";//主键ID
        $("#stlAmt").val(formatCurrency(${stlAmt}));
        $("#actStlAmt").val(formatCurrency(${actStlAmt}));
        
        $("#insPlcStl_form").ligerForm({
            validate: true
        });
        /*保存*/
        $("#saveInsPlcStl_Btn").click(function (event) {
            var form = liger.get("insPlcStl_form");
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = form.getData();
            data['actStlAmt'] = data['actStlAmt'].replace(',', '');
            data['stlAmt'] = data['stlAmt'].replace(',', '');
            $.ligerDialog.hide();
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: '<%=path%>/insurance/insPlcStl/modify.do?id=' + insPlcStlId,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        parent.$("#searchBtn").click();
                        frameElement.dialog.close();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    });
    
    
    /**
     * 格式化金额
     */
    function formatCurrency(num) {
        if (!num) return "0.00";
        num = num.toString().replace(/\$|\,/g, '');
        if (isNaN(num))
            num = "0.00";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num + 0.50000000001);
        cents = num % 100;
        num = Math.floor(num / 100).toString();
        if (cents < 10)
            cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
            num = num.substring(0, num.length - (4 * i + 3)) + ',' +
                    num.substring(num.length - (4 * i + 3));
        return (((sign) ? '' : '-') + '' + num + '.' + cents);
    }
</script>
</body>
</html>
